package SparkTest;

import Dao.MysqlDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.function.Function;

public class MysqlTest {
    public static void main(String[] args) throws SQLException {
        HashMap<String,String> map ;
        map = (HashMap<String, String>) MysqlDao.executeQuery("select * from key_value", new Function() {
            @Override
            public Object apply(Object o) {
                ResultSet rs = (ResultSet) o;
                HashMap<String,String> map = new HashMap<>();
                try {
                    while (rs.next()){
                        map.put(rs.getString(1), rs.getString(2));
                    }
                    return map;
                } catch (SQLException e){
                    e.printStackTrace();
                    return null;
                }
            }
        });
        for (String key:map.keySet()) {
            System.out.println(key + ":" + map.get(key));
            
        }
//        System.out.println(MysqlDao.executeUpdate("insert into users(userName,password)" +
//                "VALUES ('nihao','123456' )"));
//        map = MysqlDao.executeQuery("select * from users");
//        for (String key:map.keySet()) {
//            System.out.println(key + ":" + map.get(key));
//
//        }
    }
}
